package com.example.jack.community.view.home.homeAdapter;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by vveng on 2017/11/30 21: 12
 *
 * @mail: vvengStruggle@163.com
 */

public class HomePpItemDecoration extends RecyclerView.ItemDecoration{
    private int space;

    public HomePpItemDecoration(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        //不是第一个的格子都设一个左边和底部的间距
        outRect.left = space;
        //由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
        int position = parent.getChildLayoutPosition(view);
        if(position==0){
            outRect.left=0;
        }
        if(position==4){
            outRect.right=space;
        }
        if(position>0&&position<4){
            outRect.left=space;
        }
    }

}
